package com.meijin.spring6.autowired.controller;

import com.meijin.spring6.autowired.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/**
 * @Author meijindeng
 * @Data 2023-09-03 21:22
 * @Description UserController控制层
 * @Version 1.0
 */
@Controller
public class UserController {

    //第一种：属性注入
    @Autowired
    private UserService userService;

    //第二种：set 注入
    /*private UserService userService;
    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }*/

    //第三种：构造方法注入
    /*private UserService userService;
    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }*/

    //第四种：形参注入
    /*private UserService userService;
    public UserController(@Autowired UserService userService) {
        this.userService = userService;
    }*/

    //第五种：只有一个有参构造方法，无注解
    /*private UserService userService;
    public UserController(UserService userService) {
        this.userService = userService;
    }*/
    //多个构造方法，测试报错
    /*public UserController() {
    }*/

    public void add() {
        System.out.println("controller add方法执行了。。。");
        userService.add();
    }
}
